package com.controller;

import com.pojo.GroupComment;
import com.pojoVO.CommentInfoVo;
import com.pojoVO.GroupCommentVO;
import com.service.CommentInfoVoService;
import com.service.GroupCommentService;
import com.service.GroupCommentVOService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "团购评价API")
@Controller
public class GroupCommentController {
    @Autowired
    private GroupCommentVOService groupCommentVOService;
    @Autowired
    private CommentInfoVoService commentInfoVoService;
    @ApiOperation(value ="添加团购评价",notes ="" )
    @PostMapping("/groupComment")
    @ResponseBody
    public ServerResponse add(CommentInfoVo commentInfoVo){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return commentInfoVoService.save(commentInfoVo);
    }
    @ApiOperation(value = "删除团购评价",notes ="修改状态")
    @DeleteMapping("/groupComment/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
      ServerResponse serverResponse = commentInfoVoService.modifyStatus(id);
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }

    @ApiOperation(value ="修改团购评价",notes ="应该用不到" )
    @PutMapping("/groupComment")
    @ResponseBody
    public ServerResponse upd(CommentInfoVo commentInfoVo){
        System.out.println(commentInfoVo);
        ServerResponse serverResponse = commentInfoVoService.modify(commentInfoVo);
        return serverResponse;
    }
    @ApiOperation(value ="根据团购评价id查询")
    @GetMapping("/groupComment/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = commentInfoVoService.getById(id);
        return serverResponse;
    }

    @ApiOperation(value ="根据团购id查询")
    @GetMapping("/groupComment/userId/{userId}")
    @ResponseBody
    public ServerResponse getByUserId(@PathVariable("userId")Integer userId){
        System.out.println(userId);
        ServerResponse serverResponse = commentInfoVoService.getByUserId(userId);
        return serverResponse;
    }

    @ApiOperation(value ="根据团购id查询")
    @GetMapping("/groupComment/groupId/{groupId}")
    @ResponseBody
    public ServerResponse findByGroupId(@PathVariable("groupId") String groupId){
        System.out.println(groupId);
        ServerResponse serverResponse = commentInfoVoService.getByGroupId(groupId);
        return serverResponse;
    }

    @ApiOperation(value ="根据团购id查询星级数")
    @GetMapping("/groupComment/getstarNumByGroupId/{groupId}")
    @ResponseBody
    public ServerResponse getstarNumByGroupId(@PathVariable("groupId") String groupId){
        System.out.println(groupId);
        ServerResponse serverResponse = commentInfoVoService.getstarNumByGroupId(groupId);
        return serverResponse;
    }
    @ApiOperation(value ="提交评价")
    @PostMapping("/groupComment/submitCommet")
    @ResponseBody
    //前端需要穿过来的参数 star，commentContext ，orderNum，avPrice，imgList
    public ServerResponse submitCommet(CommentInfoVo  commentInfoVo){
        System.out.println(commentInfoVo);
        ServerResponse serverResponse = commentInfoVoService.submitCommet(commentInfoVo);
        return serverResponse;
    }
    @ApiOperation(value ="回复消息，")
    @PostMapping("/groupComment/saveReply")
    @ResponseBody
    /*前端需要穿过来的参数 userId，写二级评论的用户id
                        commentContext ，二级评论的内容
                        replyUserId，收到评论的用户id
                        parentId   一级评论id
        */
    public ServerResponse saveReply(CommentInfoVo commentInfoVo){
        System.out.println(commentInfoVo);
        ServerResponse serverResponse = commentInfoVoService.saveReply(commentInfoVo);
        return serverResponse;
    }

    @ApiOperation(value ="根据评论id查询对应的二级评论")
    @PostMapping("/groupComment/parentId")
    @ResponseBody
    //前端需要穿过来的参数 parentId，page
    public ServerResponse findByParentId(String parentId,Integer page){
        System.out.println(parentId);
        ServerResponse serverResponse = commentInfoVoService.findByParentId(parentId,page);
        return serverResponse;
    }

    @ApiOperation(value ="根据replyuserid查询回复该用户的消息")
    @GetMapping("/groupComment/getByReplyUserId/{replyUserId}")
    @ResponseBody

    public ServerResponse getByReplyUserId(@PathVariable Integer replyUserId){
        System.out.println(replyUserId);
        return commentInfoVoService.getByReplyUserId(replyUserId);
    }






    @ApiOperation(value ="查询团购评价信息")
    @GetMapping("/groupComment")
    @ResponseBody
    public ServerResponse findAll(){
        ServerResponse serverResponse = commentInfoVoService.getAll();
        return serverResponse;
    }

    @ApiOperation(value = "获得团购评价信息的主页面",notes = "团购评价信息端")
    @GetMapping("/groupComment/backhome")
    public String goUserBackHome(Model model){
        ServerResponse serverResponse = commentInfoVoService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/group/groupcommentbackhome";
    }

    @GetMapping("/group/commentall/{id}")
    @ResponseBody
    public ServerResponse getCommentAll(@PathVariable("id") Integer userId){
      return   groupCommentVOService.getCommentMsg(userId);
    }
}
